/** @file    SecurityAuthenticationShell.cpp
 *  @author  Alessandro Polo
 *  @version $Id: SecurityAuthenticationShell.cpp 2732 2010-07-06 03:18:11Z alex $
 *  @brief
 * File containing methods for the wosh::security::SecurityAuthenticationShell class.
 * The header for this class can be found in SecurityAuthenticationShell.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

 #include <framework/security/SecurityAuthenticationShell.h>

 #include <core/UserManager.h>
// #include <core/User.h>
 #include <core/ObjectAllocator.h>


using namespace std;
namespace wosh {
 namespace security {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::security::SecurityTokenShell, "wosh::SecurityToken", _SecurityTokenShell_VERSION, _static_SecurityTokenShell)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::security::SecurityTokenProviderShell, "wosh::SecurityTokenProvider", _SecurityTokenShell_VERSION, _static_SecurityTokenProviderShell)

SecurityTokenProviderShell::SecurityTokenProviderShell()
	: SecurityTokenProvider() {
 }
SecurityTokenProviderShell::SecurityTokenProviderShell( const SecurityTokenProviderShell& m )
	: SecurityTokenProvider(m) {
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

WRESULT SecurityTokenProviderShell::validateShell( std::string& wosh_user, std::string* os_user ) {

	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

SecurityToken* SecurityTokenProviderShell::createToken() const {
	SecurityTokenShell* st = new SecurityTokenShell();
	return st;
 }
/*
SecurityTokenShell* SecurityTokenProviderShell::generateToken( const std::string& wosh_user, const Object* object ) const {
	if ( !UserManager::isUser(wosh_user) ) return NULL;
	SecurityTokenShell* st = new SecurityTokenShell();
	st->user_name = wosh_user;
	if ( object != NULL )
		st->creator_uuid = object->getEntityID();
	st->authenticator_classname = className();
	st->authenticator_ver = _SecurityTokenShell_VERSION;
	return st;
 }
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::security::SecurityTokenAuthenticatorShell, "wosh::SecurityTokenAuthenticator", _SecurityTokenShell_VERSION, _static_SecurityTokenAuthenticatorShell)

SecurityTokenAuthenticatorShell::SecurityTokenAuthenticatorShell()
	: SecurityTokenAuthenticator() {
 }
//SecurityTokenAuthenticatorShell::SecurityTokenAuthenticatorShell( const SecurityTokenAuthenticatorShell& m )
//	: SecurityTokenAuthenticator(m) {
// }

bool SecurityTokenAuthenticatorShell::isSupported( const char* provider_classname, double version ) const {
	if ( provider_classname == NULL ) return false;
	if ( strcmp(provider_classname, SecurityTokenShell::className()) != 0 ) return false;
	if ( version != 0.0 && version > _SecurityTokenShell_VERSION ) return false;
	return true;
 }

WRESULT SecurityTokenAuthenticatorShell::validateToken( const SecurityToken* token ) const {
	return WRET_ERR_INTERNAL;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////


 






























/*



 WOSH_REGISTER(wosh::security::SecurityAuthenticationShell, "wosh::SecurityAuthentication", 1.0, _static_SecurityAuthenticationShell )

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS

SecurityAuthenticationShell::SecurityAuthenticationShell( const std::string& pwd )
	: SecurityAuthentication() {
	this->Shell = pwd;
	this->Shell_proto = "plain";
 }

SecurityAuthenticationShell::SecurityAuthenticationShell( const SecurityAuthenticationShell& m )
	: SecurityAuthentication(m) {
	this->Shell = m.Shell;
	this->Shell_proto = m.Shell_proto;
 }

//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

WRESULT SecurityAuthenticationShell::validate( const wosh::User* user ) const {
	if ( user == NULL ) return WRET_ERR_PARAM;
	bool valid = user->isValidShell( this->Shell, this->Shell_proto );
	if ( valid )
		return WRET_OK;
	return WRET_ERR_PARAM;
 }
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 }; // namespace security
}; // namespace wosh
